﻿using System;
using System.Threading.Tasks;

namespace SP.DataExchange.ServiceBus
{
    public interface IServiceBus : IDisposable
    {
        void Publish<T>(T message) where T : class;

        void Publish<T>(T message, string topic) where T : class;

        Task PublishAsync<T>(T message) where T : class;

        Task PublishAsync<T>(T message, string topic) where T : class;

        /// <summary>
        /// 订阅消息
        /// </summary>
        /// <typeparam name="T">消息实体类型</typeparam>
        /// <param name="subscriptionId"></param>
        /// <param name="onMessage">接收消息后的动作</param>
        /// <param name="prefetchCount">预取数量</param>
        /// <param name="topic">主题</param>
        /// <param name="autoDelete"></param>
        /// <param name="priority"></param>
        void Subscribe<T>(string subscriptionId, Action<T> onMessage, ushort? prefetchCount = null, string topic = null, bool? autoDelete = null, int? priority = null) where T : class;

        /// <summary>
        /// 订阅消息
        /// </summary>
        /// <typeparam name="T">消息实体类型</typeparam>
        /// <param name="onMessage">接收消息后的动作</param>
        /// <param name="prefetchCount">预取数量</param>
        /// <param name="topic">主题</param>
        /// <param name="autoDelete"></param>
        /// <param name="priority"></param>
        void Subscribe<T>(Action<T> onMessage, ushort? prefetchCount = null, string topic = null, bool? autoDelete = null, int? priority = null) where T : class;
    }
}
